package com.itcast.demo_one

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class PageTwoActivity : AppCompatActivity() {

    // 定义一个常量
    private val TAG = "itHeiMa-PageA"

    @SuppressLint("MissingInflatedId", "SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Log.d(TAG, "onCreate------page22222")

        enableEdgeToEdge()
        setContentView(R.layout.activity_page_two)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 1. 接收上一个页面传递的参数
        val name = intent.getStringExtra("name")
        var age = intent.getIntExtra("age", 0)
        findViewById<TextView>(R.id.tv_page_two).text = "姓名：$name，年龄：$age"

        findViewById<Button>(R.id.btn_back).setOnClickListener {

            // 创建返回给上一个Activity的Intent
            // 这里不需要指定目标类，因为只是返回结果数据
            val resultIntent = Intent().apply {
                putExtra("result_data", "66667777788888")
            }
            // 设置结果码和数据
            setResult(RESULT_OK, resultIntent)

            finish()
        }
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart------page22222")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume------page22222")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause------page22222")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop------page22222")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy------page22222")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(TAG, "onRestart------page22222")
    }
}